/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import Data.DatVeOnline;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author bienphongvnn
 */
public class DatVeOnlineModel {
     public static void Them(DatVeOnline n) throws SQLException{
         Connection conn = ConnectionProvider.Connect();
        try{
          
            String sql = "INSERT INTO datve(KhachHang, NgayDat, TuyenTau, ChuyenTau, LoaiTau, LoaiToa) VALUES(?,?,?,?,?,?)";
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setString(1, n.KhachHang);
            pst.setDate(2, n.NgayDat);
            pst.setString(3, n.TuyenTau);
            pst.setString(4, n.ChuyenTau);
            pst.setInt(5, n.LoaiTau);
            pst.setInt(6, n.LoaiToa);
            pst.executeUpdate();
            pst.close();
        }
        catch(Exception ex){
            ex.printStackTrace();
            ex.getMessage();
        }
        finally
        {
                conn.close();
        }
    }
    
    
    public static ArrayList<DatVeOnline> ListToaTau() {	
        ArrayList<DatVeOnline> ds = new ArrayList<DatVeOnline>();
        Connection con = ConnectionProvider.Connect();
	try {
            String sql = "select distinct tt.MaToa from toatau tt, doantau dt where tt.MaTau = dt.MaTau";
            Statement statement	= con.createStatement();	
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){	
//                DatVeOnline toa = new DatVeOnline();
//                toa.MaToa = rs.getString("MaToa");
//                ds.add(toa);
                } 
            con.close();
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());	
        }
        finally
        {
           
        }
        return	ds;	
    }
    
}
